package com.jd.sunny.java.multithreading.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.apache.log4j.Logger;

/**
 * @author :����
 * @ClassName:TestCallable
 * @Description: �����з���ֵ���߳�
 * @date :2012-8-21����10:58:37
 */

public class TestCallable {

    final static Logger logger = Logger.getLogger(TestThread.class);

    /**
     * @param args
     * @throws ExecutionException
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        //�����̳߳�
        ExecutorService pool = Executors.newFixedThreadPool(2);
        //����}���з���ֵ������
        Callable c1 = new MyCallable("sunlin");
        Callable c2 = new MyCallable("xiaozhi");
        //ִ�в�����Future����
        Future f1 = pool.submit(c1);
        Future f2 = pool.submit(c2);
        //�ж��Ƿ���ɣ������ɣ���Future�����ȡ����ֵ��������̨
        if (f1.isDone() && f2.isDone()) {
            logger.info("C1" + f1.get().toString());
            logger.info("C2" + f2.get().toString());
        }

        //�ر��̳߳�
        pool.shutdown();
    }
}


class MyCallable implements Callable {

    private String name;

    /**
     *
     */
    public MyCallable(String name) {
        this.name = name;
    }

    public Object call() throws Exception {
        //��������񣬷���ֵ��object��������get()�õ�
        return "���񷵻����ݣ�" + name;
    }

}